package com.atguigu.chaptar6

object $05_WordCountLow {
  //简单的wordcount案例
  def main(args: Array[String]): Unit = {
    val list = List("Hbase Kafka","Scala Hbase", "Hello Scala", "Hello")
    //1.元素切分map 扁平化flat   List(Hbase, Kafka, Scala, Hbase, Hello, Scala, Hello)
    val list1 = list.flatMap(_.split(" "))
    //2.分组groupBy Map(Kafka -> List(Kafka), Hello -> List(Hello, Hello), Hbase -> List(Hbase, Hbase), Scala -> List(Scala, Scala))
    val map = list1.groupBy(x => x)
    //3.map  Map(Kafka -> 1, Hello -> 2, Hbase -> 2, Scala -> 2)
    val result = map.map(x=>(x._1,x._2.size))
    //4.结果展示
    result.foreach(println(_))

    //一气呵成
    list.flatMap(_.split(" ")).groupBy(x=>x).map(x=>(x._1,x._2.size)).foreach(println(_))
  }

}
